import 'package:fate_blind_box/ui/user/matchMaker/otherMaker.dart';
import 'package:fate_blind_box/utils/common_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../theme/theme_color.dart';
import '../../../widget/icon_text.dart';

class MakerUpgradePage extends StatefulWidget {
  final Map userInfo;
  final String level;

  const MakerUpgradePage(this.userInfo, this.level, {Key? key})
      : super(key: key);

  @override
  State<MakerUpgradePage> createState() => _MakerUpgradePageState();
}

class _MakerUpgradePageState extends State<MakerUpgradePage> {
  final List _listData = [
    {
      'img': 'images/rexinM.png',
      'title': '热心红娘',
      "sub": '实名认证后可申请，可获得\n推广奖励',
      'button': '申请',
      'level': 1
    },
    {
      'img': 'images/rexinM.png',
      'title': '热心红娘',
      "sub": '实名认证后可申请，可获得\n推广奖励',
      'button': '申请',
      'level': 2
    },
    {
      'img': 'images/yinpaiM.png',
      'title': '银牌红娘',
      "sub": '银牌红娘，可获得更多奖励',
      'button': '申请',
      'level': 3
    },
    {
      'img': 'images/jinpaiM.png',
      'title': '金牌红娘',
      "sub": '金牌红娘，可获得更多奖励',
      'button': '申请',
      'level': 4
    },
    {
      'img': 'images/zhizunM.png',
      'title': '至尊红娘',
      "sub": '至尊红娘，可获得更多奖励',
      'button': '申请',
      'level': 5
    },
  ];

  final List _listDataBuss = [
    {
      'img': 'images/aixinM.png',
      'title': '普通红娘',
      "sub": '上传营业执照',
      'button': '申请',
      'level': 1
    },
    {
      'img': 'images/rexinM.png',
      'title': '热心红娘',
      "sub": '营业执照认证',
      'button': '申请',
      'level': 2
    },
    {
      'img': 'images/yinpaiM.png',
      'title': '银牌红娘',
      "sub": '银牌红娘，可获得更多奖励',
      'button': '申请',
      'level': 3
    },
    {
      'img': 'images/jinpaiM.png',
      'title': '金牌红娘',
      "sub": '金牌红娘，可获得更多奖励',
      'button': '申请',
      'level': 4
    },
    {
      'img': 'images/zhizunM.png',
      'title': '至尊红娘',
      "sub": '至尊红娘，可获得更多奖励',
      'button': '申请',
      'level': 5
    },
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print('vvvv ${widget.userInfo['level']}');
  }

  @override
  Widget build(BuildContext context) {
    return AppWidget.navTitleBar(
      bgColor: const Color(0xFFF9F9F9),
      title: widget.userInfo['matchType'] == 1 ? '红娘升级' : '商家红娘',
      childWidget: ListView.builder(
        itemBuilder: (_, index) {
          return widget.userInfo['matchType'] == 1
              ? _buildItems(_listData?[index], index)
              : _buildItems(_listDataBuss?[index], index);
        },
        itemCount: _listData.length,
      ),
    );
  }

  /// 功能按钮
  Widget _buildActionButton(String s, String id, bool isDiverder) {
    return GestureDetector(
        onTap: () {},
        child: s == ""
            ? Container(
                height: 5,
                color: ThemeColor.dividerColor,
              )
            : Container(
                height: 52,
                margin: const EdgeInsets.symmetric(horizontal: 14),
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(
                  width: 1,
                  color: isDiverder == true
                      ? ThemeColor.dividerColor
                      : Colors.white,
                ))),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: [
                        Text(
                          s,
                          style: TextStyle(
                              color: ThemeColor.textColor, fontSize: 16),
                        ),
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        id == 'makerLevel'
                            ? IconText(
                                widget.level,
                                style: const TextStyle(
                                    fontSize: 14, color: Color(0xFFB5B5B5)),
                                icon: Container(
                                  padding: const EdgeInsets.only(left: 5),
                                  child: Image.asset(
                                    'images/maker_${widget.userInfo['level'] ?? 1}.png',
                                    width: 21,
                                    height: 21,
                                  ),
                                ),
                                beforeText: false,
                              )
                            : Container(),
                        id == 'date'
                            ? Text(
                                widget.userInfo['validDate'],
                                style: const TextStyle(
                                    fontSize: 14, color: Color(0xFFB5B5B5)),
                              )
                            : Container(),
                        id == 'makerAgainMoney'
                            ? Icon(
                                Icons.arrow_forward_ios,
                                color: ThemeColor.textColorSecond,
                                size: 15,
                              )
                            : Container()
                      ],
                    ),
                  ],
                ),
              ));
  }

  _buildItems(Map map, int index) {
    return index == 0
        ? Container(
            margin: const EdgeInsets.fromLTRB(15, 10, 15, 0),
            decoration: ShapeDecoration(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(5),
              ),
              color: Colors.white,
            ),
            child: Column(
              children: [
                _buildActionButton("红娘等级", 'makerLevel', false),
                _buildActionButton("有效日期", 'date', false),
                _buildActionButton("红娘续费", 'makerAgainMoney', false),
              ],
            ),
          )
        : GestureDetector(
            child: Container(
            height: 95,
            margin: const EdgeInsets.fromLTRB(15, 10, 15, 0),
            decoration: ShapeDecoration(
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(5),
              ),
              color: Colors.white,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 10),
                  child: Image.asset(
                    map['img'],
                    width: 49,
                    height: 49,
                    fit: BoxFit.cover,
                  ),
                ),

                // const SizedBox(
                //   width: 5,
                // ),
                Expanded(
                  child: Container(
                    // padding: const EdgeInsets.symmetric(vertical: 10),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          map["title"] ?? "",
                          style: TextStyle(
                            color: ThemeColor.textColor,
                            fontSize: 16,
                          ),
                        ),
                        const SizedBox(
                          height: 7,
                        ),
                        Text(
                          map["sub"] ?? "",
                          style: TextStyle(
                            color: ThemeColor.checkNormalColor,
                            fontSize: 11,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),

                GestureDetector(
                  onTap: () async {
                    print('${widget.userInfo['level']}    ${map['level']}');
                    if (map['level'] > widget.userInfo['level']) {
                      Navigator.of(context).push(MaterialPageRoute(
                          builder: (builder) =>
                              widget.userInfo['matchType'] == 1
                                  ? otherMakerUIWidget(
                                      _listData[index]['title'], '个人红娘',isUpdate: true,)
                                  : otherMakerUIWidget(
                                      _listDataBuss[index]['title'], '商家红娘',isUpdate: true,)));
                    }
                  },
                  child: Container(
                    height: 32,
                    margin: const EdgeInsets.only(right: 8),
                    decoration: ShapeDecoration(
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20),
                      ),
                      color: map['level'] > widget.userInfo['level']
                          ? ThemeColor.appColor
                          : const Color(0xFFF8F8F8),
                    ),
                    alignment: Alignment.center,
                    padding: const EdgeInsets.symmetric(horizontal: 12),
                    child: Text(
                      map['button'],
                      style: TextStyle(
                          color: map['level'] > widget.userInfo['level']
                              ? Colors.white
                              : const Color(0xFFAAAAAA),
                          fontSize: 14),
                    ),
                  ),
                ),
              ],
            ),
          ));
  }
}
